import 'package:dsp_bt_audio/lang/my_i19n.dart';
import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';

import '../common/dialog.dart';
import '../tool/assets.dart';

class DialogInput extends DialogWidget {
  void Function(String)? onEnter;
  DialogInput({super.key, this.onEnter});
  @override
  DialogInputState createState() => DialogInputState();
}

class DialogInputState<T extends DialogInput> extends DialogWidgetState<T> {
  final _textControlller = TextEditingController();
  @override
  void initState() {
    super.initState();
    _textControlller.text = I19n.i.appname;
    _textControlller.addListener(() {
      String text = _textControlller.text;
    });
  }

  @override
  double get height => 180;
  @override
  // TODO: implement padding
  EdgeInsets get padding => EdgeInsets.only(left: 30, right: 30, bottom: 10);
  @override
  Widget get child {
    return Container(
      child: Column(
        spacing: 40,
        children: [
          Container(
            // color: Colors.red,
            decoration: BoxDecoration(
              border: BoxBorder.all(color: Colors.black, width: 0.4),
              borderRadius: BorderRadius.circular(5),
            ),
            height: 30,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  child: Container(
                    height: 30,
                    child: TextField(
                      textAlign: TextAlign.center,
                      controller: _textControlller,
                      decoration: InputDecoration(
                        contentPadding: EdgeInsets.symmetric(vertical: 12, horizontal: 0),
                        border: InputBorder.none,
                        enabledBorder: InputBorder.none,
                        focusedBorder: InputBorder.none,
                        errorBorder: InputBorder.none,
                        disabledBorder: InputBorder.none,
                      ),
                    ),
                  ),
                ),
                Align(
                  alignment: Alignment.bottomCenter,
                  child: Container(
                    height: 30,
                    width: 60,
                    decoration: BoxDecoration(
                      border: Border(
                        left: BorderSide(
                          color: Colors.black, // 边框颜色
                          width: 0.5, // 边框宽度
                        ),
                      ),
                      borderRadius: BorderRadius.circular(0),
                    ),
                    child: Center(child: Text('.DSP')),
                  ),
                ),
              ],
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [I19n.i.yes, I19n.i.no].map(($0) {
              bool isyes = $0 == I19n.i.yes;
              return Container(
                width: 60,
                height: 22,
                decoration: BoxDecoration(
                  color: isyes ? Color_theme : Colors.white,
                  border: BoxBorder.all(color: Color_theme, width: 1),
                  borderRadius: BorderRadius.circular(4),
                ),
                child: Material(
                  color: Colors.transparent,
                  child: InkWell(
                    splashColor: isyes ? Colors.white.withAlpha(100) : Color_theme.withAlpha(100),
                    highlightColor: isyes ? Colors.white.withAlpha(100) : Color_theme.withAlpha(100),
                    onTap: () {
                      Navigator.pop(context);
                      if (isyes) {
                        widget.onEnter?.call(_textControlller.text);
                      }
                    },
                    child: Center(
                      child: Text($0, style: TextStyle(color: isyes ? Colors.white : Colors.black)),
                    ),
                  ),
                ),
              );
            }).toList(),
          ),
        ],
      ),
    );
  }
}
